import {
  JupiterUrlResource,
  JupiterUrlResourceQuery,
  JupiterPermissionUrl,
  JupiterPermissionUrlQuery,
} from '../types/urlResourceTypes';
import request from 'utils/request';

// 获取URL资源列表
export const fetchUrlResourceList = (params: JupiterUrlResourceQuery) => {
  return request.post('/url-resources/page', params);
};

// 获取所有URL资源
export const fetchAllUrlResources = () => {
  return request.get('/url-resources');
};

// 根据UUID获取URL资源
export const fetchUrlResourceById = (uuid: string) => {
  return request.get(`/url-resources/${uuid}`);
};

// 创建URL资源
export const createUrlResource = (data: Partial<JupiterUrlResource>) => {
  return request.post('/url-resources', data);
};

// 更新URL资源
export const updateUrlResource = (uuid: string, data: Partial<JupiterUrlResource>) => {
  return request.put(`/url-resources/${uuid}`, data);
};

// 删除URL资源
export const deleteUrlResource = (uuid: string) => {
  return request.delete(`/url-resources/${uuid}`);
};

// 权限URL关联相关接口
export const fetchPermissionUrlList = (params: JupiterPermissionUrlQuery) => {
  return request.post('/permission-urls/page', params);
};

export const createPermissionUrl = (data: Partial<JupiterPermissionUrl>) => {
  return request.post('/permission-urls', data);
};

export const updatePermissionUrl = (uuid: string, data: Partial<JupiterPermissionUrl>) => {
  return request.put(`/permission-urls/${uuid}`, data);
};

export const deletePermissionUrl = (uuid: string) => {
  return request.delete(`/permission-urls/${uuid}`);
};

export const fetchPermissionUrlsByPermission = (permissionUuid: string) => {
  return request.get(`/permission-urls/permission/${permissionUuid}`);
};

export const fetchPermissionUrlsByUrlResource = (urlResourceUuid: string) => {
  return request.get(`/permission-urls/url-resource/${urlResourceUuid}`);
};

export const assignUrlsToPermission = (permissionUuid: string, urlResourceUuids: string[], isRequired: boolean) => {
  return request.post('/permission-urls/assign', {
    permissionUuid,
    urlResourceUuids,
    isRequired,
  });
};
